package com.jie.mongodb.service;

import com.jie.mongodb.entity.SportTrack;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RecordRepository extends MongoRepository<SportTrack, String> {
    /**
     * 根据trackId和userId进行条件查询，并按recordTime升序排序
     * @param trackId
     * @param userId
     * @return
     */
    List<SportTrack> findByTrackIdAndUserIdOrderByRecordTimeAsc(Integer trackId, Integer userId);

    /**
     * 根据trackId和userId进行条件查询，并按recordTime降序排序
     * @param trackId
     * @param userId
     * @return
     */
    List<SportTrack> findByTrackIdAndUserIdOrderByRecordTimeDesc(Integer trackId, Integer userId);

    /**
     * 获取最老的一条数据
     * @param trackId
     * @param userId
     * @return
     */
    SportTrack findTopByTrackIdAndUserIdOrderByRecordTimeAsc(Integer trackId, Integer userId);

    /**
     * 获取最新的记录
     * @param trackId
     * @param userId
     * @return
     */
    SportTrack findTopByTrackIdAndUserIdOrderByRecordTimeDesc(Integer trackId, Integer userId);

    /**
     * 根据trackId和userId进行条件查询，并按recordTime升序排序，并添加分页
     * @param trackId
     * @param userId
     * @param pageable
     * @return
     */
    Page<SportTrack> findByTrackIdAndUserIdOrderByRecordTimeAsc(Integer trackId, Integer userId, Pageable pageable);

    /**
     * 根据trackId和userId进行条件查询，并按recordTime降序排序，并添加分页
     * @param trackId
     * @param userId
     * @param pageable
     * @return
     */
    Page<SportTrack> findByTrackIdAndUserIdOrderByRecordTimeDesc(Integer trackId, Integer userId, Pageable pageable);
}